<template>
  <el-dialog
    class="base-dialog readonly"
    :custom-class="'panna-dialog_medium'"
    title="选择委托样品检测"
    :visible.sync="dialogVisible"
    :append-to-body="true"
    :before-close="handleClose"
  >
    <p slot="title">选择委托样品检测</p>
    <div>
      <el-table ref="table" border :data="tableData" style="width: 100%" height="500px">
        <el-table-column prop="sampleTypeName" label="样品类别">
          <template slot-scope="scope">
            <a style="color: blue" @click="clicksampleTypeName(scope.row)">
              {{
              scope.row.sampleTypeName
              }}
            </a>
          </template>
        </el-table-column>
        <el-table-column prop="orderNum" label="委托单号" />
        <el-table-column prop="sampleName" label="样品名称" />
        <el-table-column prop="detectionItemName" label="检测项目名称" />
      </el-table>
      <!-- 分页 -->
      <BasePagination
        :total="pageInfo.total"
        :current-page="pageInfo.pageIndex"
        @changePage="changePage"
        @sizeChange="sizeChange"
      />
    </div>
  </el-dialog>
</template>

<script>
import { getList } from "../../../api/EntrustManage/EntrustSampleDetection.js";
export default {
  name: "ChioceEntrustSampleDetection",
  components: {},
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
    entrustId: {
      type: [String, Number],
      default: "",
    },
  },
  data() {
    return {
      entrustSampleDetection: {},
      entrustSampleDetectionId: "",
      detectionItemIdList: [],
      isShowDialog: false,
      dialogVisible: false,
      tableData: [],
      filterForm: {
        EntrustOrderId: "",
        QueryEntrustSampleDetectionEnum: 0,
      },
      pageInfo: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  watch: {
    dialogFormVisible(val) {
      this.dialogVisible = val;
      if (val) {
        this.init();
      }
    },
    dialogVisible(val) {
      this.$emit("update:dialogFormVisible", val);
    },
  },
  methods: {
    // 点击样品类别名称
    clicksampleTypeName(row) {
      var data = {};
      this.entrustSampleDetection = row;
      this.entrustSampleDetectionId = row.id;
      this.detectionItemIdList = row.detectionItemIdList;
      data.entrustSampleDetection = row;
      data.entrustSampleDetectionId = row.id;
      data.detectionItemIdList = row.detectionItemIdList;
      this.$emit("closeChioseEntrustSampleDetection", data);
      this.handleClose();
    },
    // 初始化
    async init() {
      this.filterForm.EntrustOrderId = this.entrustId;
      getList({ ...this.filterForm, ...this.pageInfo }).then((res) => {
        this.tableData = res.data.dataList ? res.data.dataList : [];
        this.pageInfo.total = res.data.total;
      });
    },
    sizeChange(val) {
      this.pageInfo.pageIndex = 1;
      this.pageInfo.pageSize = val;
      this.init();
    },
    // 切换页码
    changePage(page) {
      this.pageInfo.pageIndex = page;
      this.init();
    },
    // 关闭弹框
    handleClose() {
      this.dialogVisible = false;
    },
  },
};
</script>

